/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.railway.app;

import com.railway.utils.RestServer;
import com.railway.utils.Toast;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.json.JSONObject;
import org.json.JSONException;

/**
 *
 * @author Kenny
 */
public class DeleteStaffPanel extends javax.swing.JPanel {

    Image imgArrow = new ImageIcon(this.getClass().getResource("/com/railway/image/arrow.png")).getImage();
    private JFileChooser chooser,jfcImageChooser;
    private FileNameExtensionFilter filter;
    private File image;
    private ImageIcon photo;
    private Image scaleImage;
    /**
     * Creates new form RoutePanel
     */
    public DeleteStaffPanel() {
        initComponents();
        setDefault();
        disableAll();
        jcbIC.setSelected(true);
    }
    
    private ImageIcon getImageFile(String url, boolean isUrl) {
        Image img;
        BufferedImage bfImg = null;
        try {
            if (isUrl) {
                String serverurl = "http://localhost/RailwayWeb/";
                img = new ImageIcon(new URL(serverurl + url)).getImage();
            } else {
                img = ImageIO.read(new File(url));
            }
            bfImg = new BufferedImage(jlblImage.getWidth(), jlblImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2d = bfImg.createGraphics();
            g2d.drawImage(img, 0, 0, jlblImage.getWidth(), jlblImage.getHeight(), this);
            g2d.dispose();
        } catch (MalformedURLException ex) {
            Logger.getLogger(PointRedemptionPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(PointRedemptionPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new ImageIcon(bfImg);
    }
    
    public void disableAll(){
        jtfICID.setEditable(true);
        jtfFirstName.setEditable(false);
        jtfLastName.setEditable(false);
        jtfDoB.setEditable(false);
        jrbMale.setEnabled(false);
        jrbFemale.setEnabled(false);
        jcbPosition.setEnabled(false);
        jtfYearEmployed.setEditable(false);
        jtfPhoneNo.setEditable(false);
        jtfEmail.setEditable(false);
        jtfAddress.setEditable(false);
        jtfCity.setEditable(false);
        jtfState.setEditable(false);
        jtfPostalCode.setEditable(false);
        jcbQuestion.setEnabled(false);
        jtfAnswer.setEditable(false);
        jlblImage.setIcon(null);
    }
    
    public void enableAll(){
        jtfICID.setEditable(true);
        jtfFirstName.setEditable(true);
        jtfLastName.setEditable(true);
        jtfDoB.setEditable(true);
        jrbMale.setEnabled(true);
        jrbFemale.setEnabled(true);
        jcbPosition.setEnabled(true);
        jtfYearEmployed.setEditable(true);
        jtfPhoneNo.setEditable(true);
        jtfEmail.setEditable(true);
        jtfAddress.setEditable(true);
        jtfCity.setEditable(true);
        jtfState.setEditable(true);
        jtfPostalCode.setEditable(true);
        jcbQuestion.setEnabled(true);
        jtfAnswer.setEditable(true);
        jbDelete.setEnabled(true);
    }
    
    public void setDefault(){
        jtfFirstName.setText(null);
        jtfLastName.setText(null);
        jtfDoB.setText(null);
        jcbPosition.setSelectedIndex(0);
        jtfYearEmployed.setText(null);
        jtfPhoneNo.setText(null);
        jtfEmail.setText(null);
        jtfAddress.setText(null);
        jtfCity.setText(null);
        jtfState.setText(null);
        jtfPostalCode.setText(null);
        jcbQuestion.setSelectedIndex(0);
        jtfAnswer.setText(null);
        jbDelete.setEnabled(false);
        jlblImage.setIcon(null);
    }
    
    public static boolean isNumeric(String str){  
        try{  
            double d = Double.parseDouble(str);  
        }  
        catch(NumberFormatException nfe){  
            return false;  
        }  
        return true;  
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgGender = new javax.swing.ButtonGroup();
        bgIndex = new javax.swing.ButtonGroup();
        jpDeleteStaff = new javax.swing.JPanel();
        jpStaffParticular = new javax.swing.JPanel();
        jlblFirstName = new javax.swing.JLabel();
        jlblLastName = new javax.swing.JLabel();
        jtfLastName = new javax.swing.JTextField();
        jlblGender = new javax.swing.JLabel();
        jrbMale = new javax.swing.JRadioButton();
        jrbFemale = new javax.swing.JRadioButton();
        jlblPosition = new javax.swing.JLabel();
        jcbPosition = new javax.swing.JComboBox();
        jlblDoB = new javax.swing.JLabel();
        jtfDoB = new javax.swing.JTextField();
        jtfICID = new javax.swing.JTextField();
        jtfFirstName = new javax.swing.JTextField();
        jbSearch = new javax.swing.JButton();
        jcbIC = new javax.swing.JCheckBox();
        jcbID = new javax.swing.JCheckBox();
        jlblYearEmployed = new javax.swing.JLabel();
        jtfYearEmployed = new javax.swing.JTextField();
        jpAddress = new javax.swing.JPanel();
        jlblAddress = new javax.swing.JLabel();
        jlblCity = new javax.swing.JLabel();
        jlblState = new javax.swing.JLabel();
        jlblPostalCode = new javax.swing.JLabel();
        jtfCity = new javax.swing.JTextField();
        jtfState = new javax.swing.JTextField();
        jtfPostalCode = new javax.swing.JTextField();
        jtfAddress = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jlblImage = new javax.swing.JLabel();
        jpSecurity = new javax.swing.JPanel();
        jlblQuestion = new javax.swing.JLabel();
        jlblAnswer = new javax.swing.JLabel();
        jcbQuestion = new javax.swing.JComboBox();
        jtfAnswer = new javax.swing.JTextField();
        jpContacts = new javax.swing.JPanel();
        jlblPhoneNo = new javax.swing.JLabel();
        jlblEmail = new javax.swing.JLabel();
        jtfPhoneNo = new javax.swing.JTextField();
        jtfEmail = new javax.swing.JTextField();
        jbDelete = new javax.swing.JButton();
        jpScheduleArrow = new javax.swing.JPanel(){
            protected void paintComponent(Graphics g){
                super.paintComponent(g);
                g.drawImage(imgArrow, 0, 0, getWidth(), getHeight(), this);
            }
        };

        bgGender.add(jrbMale);
        bgGender.add(jrbFemale);

        bgIndex.add(jcbIC);
        bgIndex.add(jcbID);

        setPreferredSize(new java.awt.Dimension(870, 460));
        setLayout(null);

        jpDeleteStaff.setBackground(new java.awt.Color(220, 220, 220));
        jpDeleteStaff.setLayout(null);

        jpStaffParticular.setBorder(javax.swing.BorderFactory.createTitledBorder("Staff Particular"));

        jlblFirstName.setText("First Name");

        jlblLastName.setText("Last Name");

        jlblGender.setText("Gender");

        jrbMale.setText("Male");

        jrbFemale.setText("Female");

        jlblPosition.setText("Position");

        jcbPosition.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "Staff" }));

        jlblDoB.setText("DoB");

        jbSearch.setText("Search");
        jbSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSearchActionPerformed(evt);
            }
        });

        jcbIC.setText("IC");
        jcbIC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbICActionPerformed(evt);
            }
        });

        jcbID.setText("ID");
        jcbID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbIDActionPerformed(evt);
            }
        });

        jlblYearEmployed.setText("Year Employed");

        javax.swing.GroupLayout jpStaffParticularLayout = new javax.swing.GroupLayout(jpStaffParticular);
        jpStaffParticular.setLayout(jpStaffParticularLayout);
        jpStaffParticularLayout.setHorizontalGroup(
            jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpStaffParticularLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jlblYearEmployed, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpStaffParticularLayout.createSequentialGroup()
                        .addComponent(jcbIC, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbID, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jlblPosition, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblGender, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblDoB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblLastName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblFirstName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpStaffParticularLayout.createSequentialGroup()
                        .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfICID, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfFirstName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfLastName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfDoB, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpStaffParticularLayout.createSequentialGroup()
                            .addComponent(jrbMale, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jrbFemale, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(jtfYearEmployed, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jcbPosition, javax.swing.GroupLayout.Alignment.LEADING, 0, 168, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpStaffParticularLayout.setVerticalGroup(
            jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpStaffParticularLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtfICID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbSearch))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbIC)
                        .addComponent(jcbID)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblFirstName)
                    .addComponent(jtfFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblLastName)
                    .addComponent(jtfLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblDoB)
                    .addComponent(jtfDoB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblGender)
                    .addComponent(jrbMale)
                    .addComponent(jrbFemale))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblPosition)
                    .addComponent(jcbPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpStaffParticularLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblYearEmployed)
                    .addComponent(jtfYearEmployed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jpDeleteStaff.add(jpStaffParticular);
        jpStaffParticular.setBounds(10, 10, 410, 260);

        jpAddress.setBorder(javax.swing.BorderFactory.createTitledBorder("Address"));

        jlblAddress.setText("Address");

        jlblCity.setText("City");

        jlblState.setText("State");

        jlblPostalCode.setText("Postal Code");

        jLabel3.setText("Picture");

        javax.swing.GroupLayout jpAddressLayout = new javax.swing.GroupLayout(jpAddress);
        jpAddress.setLayout(jpAddressLayout);
        jpAddressLayout.setHorizontalGroup(
            jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpAddressLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblCity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblState, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblPostalCode, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtfState, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                        .addComponent(jtfCity, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtfPostalCode, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jlblImage, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtfAddress, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(79, Short.MAX_VALUE))
        );
        jpAddressLayout.setVerticalGroup(
            jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpAddressLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblAddress)
                    .addComponent(jtfAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblCity)
                    .addComponent(jtfCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblState)
                    .addComponent(jtfState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblPostalCode)
                    .addComponent(jtfPostalCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpAddressLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jlblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jpDeleteStaff.add(jpAddress);
        jpAddress.setBounds(430, 10, 430, 260);

        jpSecurity.setBorder(javax.swing.BorderFactory.createTitledBorder("Security"));

        jlblQuestion.setText("Question");

        jlblAnswer.setText("Answer");

        jcbQuestion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "What was your childhood nickname?", "What street did you live on in third grade?", "In what city or town did your mother and father meet?", "What was the last name of your third grade teacher?", "What time of the day were you born?", "In what city or town was your first job?", "What was your favorite place to visit as a child?" }));

        javax.swing.GroupLayout jpSecurityLayout = new javax.swing.GroupLayout(jpSecurity);
        jpSecurity.setLayout(jpSecurityLayout);
        jpSecurityLayout.setHorizontalGroup(
            jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpSecurityLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jlblQuestion, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                    .addComponent(jlblAnswer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jcbQuestion, 0, 251, Short.MAX_VALUE)
                    .addComponent(jtfAnswer))
                .addContainerGap(78, Short.MAX_VALUE))
        );
        jpSecurityLayout.setVerticalGroup(
            jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpSecurityLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblQuestion)
                    .addComponent(jcbQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpSecurityLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblAnswer)
                    .addComponent(jtfAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jpDeleteStaff.add(jpSecurity);
        jpSecurity.setBounds(430, 280, 430, 130);

        jpContacts.setBorder(javax.swing.BorderFactory.createTitledBorder("Contacts"));

        jlblPhoneNo.setText("Phone No");

        jlblEmail.setText("Email");

        javax.swing.GroupLayout jpContactsLayout = new javax.swing.GroupLayout(jpContacts);
        jpContacts.setLayout(jpContactsLayout);
        jpContactsLayout.setHorizontalGroup(
            jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpContactsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jlblPhoneNo, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                    .addComponent(jlblEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfPhoneNo, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        jpContactsLayout.setVerticalGroup(
            jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpContactsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblPhoneNo)
                    .addComponent(jtfPhoneNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpContactsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblEmail)
                    .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, Short.MAX_VALUE))
        );

        jpDeleteStaff.add(jpContacts);
        jpContacts.setBounds(10, 280, 410, 130);

        jbDelete.setText("Delete");
        jbDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDeleteActionPerformed(evt);
            }
        });
        jpDeleteStaff.add(jbDelete);
        jbDelete.setBounds(760, 410, 63, 23);

        add(jpDeleteStaff);
        jpDeleteStaff.setBounds(0, 20, 870, 440);

        javax.swing.GroupLayout jpScheduleArrowLayout = new javax.swing.GroupLayout(jpScheduleArrow);
        jpScheduleArrow.setLayout(jpScheduleArrowLayout);
        jpScheduleArrowLayout.setHorizontalGroup(
            jpScheduleArrowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );
        jpScheduleArrowLayout.setVerticalGroup(
            jpScheduleArrowLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        add(jpScheduleArrow);
        jpScheduleArrow.setBounds(360, 0, 150, 20);
    }// </editor-fold>//GEN-END:initComponents

    private void jbSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSearchActionPerformed
        if(jtfICID.getText().length()!=0){
            if(isNumeric(jtfICID.getText())){
                if(jcbID.isSelected()){
                    String staffInfo = RestServer.httpGet("searchStaffById", ""+jtfICID.getText());
                    try{
                        JSONObject json = new JSONObject(staffInfo);
                        JSONObject content = json.getJSONObject("content");

                        if(jtfICID.getText().length()!=0){
                            jtfFirstName.setText(content.getString("firstname"));
                            jtfLastName.setText(content.getString("lastname"));
                            jtfDoB.setText(content.getString("dob"));
                            if(content.getString("gender").equals("M")){
                                jrbMale.setSelected(true);
                            }else{
                                jrbFemale.setSelected(false);
                            }
                            
                            for(int i =0 ; i<jcbPosition.getItemCount();i++){
                                if(content.getString("position").equals(jcbPosition.getItemAt(i))){
                                    jcbPosition.setSelectedIndex(i);
                                }
                            }

                            for(int i =0 ; i<jcbQuestion.getItemCount();i++){
                                if(content.getString("question").equals(jcbQuestion.getItemAt(i))){
                                    jcbQuestion.setSelectedIndex(i);
                                }
                            }
                            
                            jlblImage.setIcon(this.getImageFile(content.getString("profilePicture"), true));
                            
                            jtfYearEmployed.setText(content.getString("yearEmployed"));
                            jtfPhoneNo.setText(content.getString("contactNo"));
                            jtfEmail.setText(content.getString("email"));
                            jtfAddress.setText(content.getString("address"));
                            jtfCity.setText(content.getString("city"));
                            jtfState.setText(content.getString("state"));
                            jtfPostalCode.setText(content.getString("postalCode"));
                            jtfAnswer.setText(content.getString("answer"));
                            Toast.makeText(getParent(), "Found!", Toast.LENGTH_LONG).display();
                            jbDelete.setEnabled(true);
                        }else{
                        }
                    }catch(JSONException ex){
                        Toast.makeText(getParent(), "Staff not found", Toast.LENGTH_LONG).display();
                        setDefault();
                    }
                }else if(jcbIC.isSelected()){
                    if(jtfICID.getText().length()==12){
                        String staffInfo = RestServer.httpGet("searchStaffByIc", ""+jtfICID.getText());
                        try{
                            JSONObject json = new JSONObject(staffInfo);
                            JSONObject content = json.getJSONObject("content");

                            if(jtfICID.getText().length()!=0){
                                jtfFirstName.setText(content.getString("firstname"));
                                jtfLastName.setText(content.getString("lastname"));
                                jtfDoB.setText(content.getString("dob"));
                                if(content.getString("gender").equals("M")){
                                    jrbMale.setSelected(true);
                                }else{
                                    jrbFemale.setSelected(false);
                                }

                                for(int i =0 ; i<jcbPosition.getItemCount();i++){
                                    if(content.getString("position").equals(jcbPosition.getItemAt(i))){
                                        jcbPosition.setSelectedIndex(i);
                                    }
                                }

                                for(int i =0 ; i<jcbQuestion.getItemCount();i++){
                                    if(content.getString("question").equals(jcbQuestion.getItemAt(i))){
                                        jcbQuestion.setSelectedIndex(i);
                                    }
                                }
                                jtfYearEmployed.setText(content.getString("yearEmployed"));
                                jtfPhoneNo.setText(content.getString("contactNo"));
                                jtfEmail.setText(content.getString("email"));
                                jtfAddress.setText(content.getString("address"));
                                jtfCity.setText(content.getString("city"));
                                jtfState.setText(content.getString("state"));
                                jtfPostalCode.setText(content.getString("postalCode"));
                                jtfAnswer.setText(content.getString("answer"));
                                Toast.makeText(getParent(), "Found!", Toast.LENGTH_LONG).display();
                                jbDelete.setEnabled(true);
                            }else{
                            }
                        }catch(JSONException ex){
                            Toast.makeText(getParent(), "Staff not found", Toast.LENGTH_LONG).display();
                            setDefault();
                        }
                    }else{
                        Toast.makeText(getParent(), "IC must be 12 numeric characters!", Toast.LENGTH_LONG).display();
                    }
                }
            }else{
                Toast.makeText(getParent(), "The ID or IC must be numeric!", Toast.LENGTH_LONG).display();
            }
        }else{
            Toast.makeText(getParent(), "Please input IC or ID to search!", Toast.LENGTH_LONG).display();
        }
    }//GEN-LAST:event_jbSearchActionPerformed

    private void jcbICActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbICActionPerformed
        jtfICID.setText(null);
        setDefault();
        disableAll();
    }//GEN-LAST:event_jcbICActionPerformed

    private void jcbIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbIDActionPerformed
        jtfICID.setText(null);
        setDefault();
        disableAll();
    }//GEN-LAST:event_jcbIDActionPerformed

    private void jbDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDeleteActionPerformed
        if(jtfICID.getText().length()!=0){
            if(jcbID.isSelected()){
                Map<String, Object> data = new HashMap<>();
                data.put("status", "Deleted");

                String b = RestServer.httpPut("deleteStaffById",data ,jtfICID.getText());
                try{
                    JSONObject json = new JSONObject(b);
                    Toast.makeText(getParent(), "Staff has been successfully deleted", Toast.LENGTH_LONG).display();
                }catch (JSONException ex) {
                    Toast.makeText(getParent(), "Staff does not exist\n Please check the Id again\n", Toast.LENGTH_LONG).display();
                    setDefault();
                }
            }else if(jcbIC.isSelected()){
                Map<String, Object> data = new HashMap<>();
                data.put("status", "Deleted");

                String b = RestServer.httpPut("deleteStaffByIc",data ,jtfICID.getText());
                try{
                    JSONObject json = new JSONObject(b);
                    Toast.makeText(getParent(), "Staff has been successfully deleted", Toast.LENGTH_LONG).display();
                }catch (JSONException ex) {
                    Toast.makeText(getParent(), "Staff does not exist\n Please check the Ic again\n", Toast.LENGTH_LONG).display();
                    setDefault();
                }
            }
        }else{
            Toast.makeText(getParent(), "Please enter IC or ID to search", Toast.LENGTH_LONG).display();
        }
    }//GEN-LAST:event_jbDeleteActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgGender;
    private javax.swing.ButtonGroup bgIndex;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton jbDelete;
    private javax.swing.JButton jbSearch;
    private javax.swing.JCheckBox jcbIC;
    private javax.swing.JCheckBox jcbID;
    private javax.swing.JComboBox jcbPosition;
    private javax.swing.JComboBox jcbQuestion;
    private javax.swing.JLabel jlblAddress;
    private javax.swing.JLabel jlblAnswer;
    private javax.swing.JLabel jlblCity;
    private javax.swing.JLabel jlblDoB;
    private javax.swing.JLabel jlblEmail;
    private javax.swing.JLabel jlblFirstName;
    private javax.swing.JLabel jlblGender;
    private javax.swing.JLabel jlblImage;
    private javax.swing.JLabel jlblLastName;
    private javax.swing.JLabel jlblPhoneNo;
    private javax.swing.JLabel jlblPosition;
    private javax.swing.JLabel jlblPostalCode;
    private javax.swing.JLabel jlblQuestion;
    private javax.swing.JLabel jlblState;
    private javax.swing.JLabel jlblYearEmployed;
    private javax.swing.JPanel jpAddress;
    private javax.swing.JPanel jpContacts;
    private javax.swing.JPanel jpDeleteStaff;
    private javax.swing.JPanel jpScheduleArrow;
    private javax.swing.JPanel jpSecurity;
    private javax.swing.JPanel jpStaffParticular;
    private javax.swing.JRadioButton jrbFemale;
    private javax.swing.JRadioButton jrbMale;
    private javax.swing.JTextField jtfAddress;
    private javax.swing.JTextField jtfAnswer;
    private javax.swing.JTextField jtfCity;
    private javax.swing.JTextField jtfDoB;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfFirstName;
    private javax.swing.JTextField jtfICID;
    private javax.swing.JTextField jtfLastName;
    private javax.swing.JTextField jtfPhoneNo;
    private javax.swing.JTextField jtfPostalCode;
    private javax.swing.JTextField jtfState;
    private javax.swing.JTextField jtfYearEmployed;
    // End of variables declaration//GEN-END:variables
}
